package com.sqin.taskflow;

import com.sqin.taskflow.config.TaskFlowConfig;
import com.sqin.taskflow.queue.TaskFlow;
import com.sqin.taskflow.task.MultiTask;
import com.sqin.taskflow.task.SubMultiTask;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

@Slf4j
public class MyTask {


    public static void main(String[] args) {
        TaskFlowConfig.listen = new MyTaskListen();

        MyCustomSingleJob myTask1 = new MyCustomSingleJob("任务1");
        MyCustomSingleJob myTask2 = new MyCustomSingleJob("任务2");

        MyCustomMultiJob myTask31 = new MyCustomMultiJob("任务31");
        MyCustomMultiJob myTask32 = new MyCustomMultiJob("任务32");
        MyCustomMultiJob myTask33 = new MyCustomMultiJob("任务33");
        MyCustomMultiJob myTask34 = new MyCustomMultiJob("任务34");
        MyCustomMultiJob myTask35 = new MyCustomMultiJob("任务35");
        List<SubMultiTask> myTask3list = new ArrayList<>();
        myTask3list.add(myTask31);
        myTask3list.add(myTask32);
        myTask3list.add(myTask33);
        myTask3list.add(myTask34);
        myTask3list.add(myTask35);
        MultiTask myTask3 = new MultiTask(myTask3list,5);

        MyCustomSingleJob myTask4 = new MyCustomSingleJob("任务4");

        TaskFlow taskFlow = new TaskFlow();
        taskFlow.put(myTask1);
        taskFlow.put(myTask2);
        taskFlow.put(myTask3);
        taskFlow.put(myTask4);

        try{
            taskFlow.run();
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }

        log.info("任务编排完成");

    }
}
